﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Reflection;

namespace TS_XY_Train_Repaire.UserCon.Report
{
    public partial class UserCon_Report_Debug_Main : DevExpress.XtraEditors.XtraForm
    {
        public string _LoadName = "";
        public string _LoadBMWID = "";
        public string _LoadMWID = "";
        public string _LoadMainID = "8";
        public UserCon_Report_Debug_Main()
        {
            InitializeComponent();
        }

        private void UserCon_Report_Pop_Main_Load(object sender, EventArgs e)
        {
            this.Text = _LoadName+"检修记录调试";
            _LoadMWID = TS_Win_Class.GetSQlFieldValue("select f_mwid from TS_TR_BU_Work_Main where f_id=" + _LoadBMWID, "f_mwid");
            Button _bt = new Button();
            string strSQL = "select f_id,f_name from TS_S_T_P_Tree where f_del=0 and f_mainid="+_LoadMainID+ " and f_type=1 and f_id in (select f_treeid from TS_S_T_P_Report_Tech where f_functype=1 and f_funcid in (select f_id from TS_TR_PS_Work_Main_Steps where f_del=0 and f_mwid=" + _LoadMWID+") and f_del=0) order by f_str_2 asc";
            SqlConnection conn = new SqlConnection(TS_Win_Class.GetSQlConnStr());
            conn.Open();
            SqlCommand comm = new SqlCommand(strSQL, conn);
            SqlDataReader read = comm.ExecuteReader();
            while (read.Read())
            {
                _bt = new Button();
                _bt.Name=read["f_id"].ToString();
                _bt.Text = read["f_name"].ToString();
                _bt.Tag = read["f_id"].ToString();
                _bt.AutoSize = true;
                //if (_LoadRMType == "0")
                //{
                _bt.Click += new System.EventHandler(this.RM_Click);
                //}
                //if (_LoadRMType == "1")
                //{
                //    _bt.Click += new System.EventHandler(this.RM_FI_Click);
                //}
                flp_Main_Report.Controls.Add(_bt);
            }
            read.Close();
            conn.Close();
            conn.Dispose();
        }

        private void RM_Click(object sender, EventArgs e)
        {
            Button _bt = (Button)sender;
            try
            {
                WIN_RegisterReport_OBJ _obj = new WIN_RegisterReport_OBJ();
                Assembly assembly = Assembly.GetExecutingAssembly();            // 实例化窗体
                Form _LoadForm = assembly.CreateInstance(TS_Win_Class.GetSQlFieldValue("select f_str_0 from TS_S_T_P_Tree where f_id=" + _bt.Tag.ToString(), "f_str_0")) as Form;
                _obj._sBMWID = _LoadBMWID;
                _obj._sRMID = _bt.Tag.ToString();
                _obj._sMainID = _LoadMainID;
                _LoadForm.Tag = _obj;
                _LoadForm.StartPosition = FormStartPosition.CenterScreen;
                _LoadForm.ShowDialog(this);
            }
            catch
            {
                MessageBox.Show(TS_Win_Class.GetSQlFieldValue("select '报表名：'+f_name+'\r调用窗体名：'+f_str_0+'\r调用报表名'+f_str_1+'\r调用失败！！' as f_name from TS_S_T_P_Tree where f_id=" + _bt.Tag.ToString(), "f_name"));
            }
        }
        private void RM_FI_Click(object sender, EventArgs e)
        {
            //Button _bt = (Button)sender;
            ////MessageBox.Show(TS_Win_Class.GetSQlFieldValue("select '报表名：'+f_name+'\r   调用窗体名：'+f_formname+'\r  调用报表名'+f_reportname as f_name from TS_S_T_P_Report_Main where f_id=" + _bt.Tag.ToString(), "f_name"));
            //try
            //{
            //    WIN_FittingsReport_OBJ _obj = new WIN_FittingsReport_OBJ();
            //    Assembly assembly = Assembly.GetExecutingAssembly();            // 实例化窗体
            //    Form _LoadForm = assembly.CreateInstance(TS_Win_Class.GetSQlFieldValue("select f_formname from TS_S_T_P_Report_Main where f_id=" + _bt.Tag.ToString(), "f_formname")) as Form;
            //    //Form _LoadForm = assembly.CreateInstance("TS_XY_Train_Repaire.Test.XtraForm1") as Form;

            //    _obj._sBMWID = _cf_BMWID;
            //    _obj._sRMID = _bt.Tag.ToString();
            //    _LoadForm.Tag = _obj;
            //    _cf_RPMID = _bt.Tag.ToString();
            //    _cf_RPMName = _bt.Text.ToString();
            //    _LoadForm.StartPosition = FormStartPosition.CenterScreen;
            //    _LoadForm.ShowDialog(this);
            //}
            //catch
            //{
            //    MessageBox.Show(TS_Win_Class.GetSQlFieldValue("select '报表名：'+f_name+'\r调用窗体名：'+f_formname+'\r调用报表名'+f_reportname+'\r调用失败！！' as f_name from TS_S_T_P_Report_Main where f_id=" + _bt.Tag.ToString(), "f_name"));
            //}
        }
    }
}